<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet"
	href="//cdn.datatables.net/1.10.2/css/jquery.dataTables.css">
<link rel="stylesheet" href="resources/css/doctor/roomlist.css">
<script type="text/javascript"
	src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript"
	src="//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">

	$(document).ready(function(){
	    $('#myTable').dataTable();
	});

	function wardout(aaaa) {
		var idx = $('.normalBtn').index(aaaa);
		var jupsoo_id = $(".jupsoo_id").eq(idx).val();
		var name = $(".name").eq(idx).val();
		var dept_name = $(".dept_name").eq(idx).val();
		var doctor_name = $(".doctor_name").eq(idx).val();
		var ward_num = $(".ward_num").eq(idx).val();
		var ward_period = $(".ward_period").eq(idx).val();
		var jupsoo_date = $(".jupsoo_date").eq(idx).val();
		var jupsoo_time = $(".jupsoo_time").eq(idx).val();
		var ward_date = $(".ward_date").eq(idx).val();
		var ward_list_id = $(".ward_list_id").eq(idx).val();
		var patient_id = $(".patient_id").eq(idx).val();
		var doctor_id = $(".doctor_id").eq(idx).val();
		var w_soonap_id = $(".w_soonap_id").eq(idx).val();
		$.ajax({
			url : 'wardout.do',
			data : 'jupsoo_id='+jupsoo_id+'&name='+name+'&dept_name='
					+dept_name+'&doctor_name='+doctor_name+'&ward_num='
					+ward_num+'&ward_period='+ward_period
					+'&jupsoo_date='+jupsoo_date+'&jupsoo_time='
					+jupsoo_time+'&ward_date='+ward_date
					+'&ward_list_id='+ward_list_id+'&patient_id='
					+patient_id+'&doctor_id='+doctor_id+'&w_soonap_id='
					+w_soonap_id,
			dataType : 'json',
			success : function(data) {
				if (data === 'yes') {
					setTimeout(reset(), 1);
				}
			}
		})
	}
		function reset() {
		$.ajax({
			url : 'roomlist2.do',
			dataType : 'json',
			success : function(n) {
				$(".roomlist_div").empty();
				var html = ""; 
				html+= "<table id='myTable' class='display'><thead><tr>";
				html+= "<th>접수번호</th>";
				html+= "<th>환자명</th>";
				html+= "<th>진료과</th>";
				html+= "<th>의사명</th>";
				html+= "<th>병실</th>";
				html+= "<th>입원기간</th>";
				html+= "<th>접수날짜</th>";
				html+= "<th>입원날짜</th>";
				html+= "<th>퇴원처리</th>";
				html+= "</tr></thead>";
				html+= "<tbody id='tbody'>";
						for (var i = 0; i < n.wardlist.length; i++) {
						html+= "<tr><td><input type='hidden' name='jupsoo_id' class='jupsoo_id' value='"+n.wardlist[i].jupsoo_id+"'>"+n.wardlist[i].jupsoo_id+"</td>";
						html+= "<td><input type='hidden' name='name' class='name' value='"+n.wardlist[i].name +"'>"+n.wardlist[i].name +"</td>";
						html+= "<td><input type='hidden' name='dept_name' class='dept_name' value='"+n.wardlist[i].dept_name +"'>"+n.wardlist[i].dept_name +"</td>";
						html+= "<td><input type='hidden' name='doctor_name' class='doctor_name' value='"+n.wardlist[i].doctor_name +"'>"+n.wardlist[i].doctor_name +"</td>";
						html+= "<td><input type='hidden' name='ward_num' class='ward_num' value='"+n.wardlist[i].ward_num+ "'>"+n.wardlist[i].ward_num+ "</td>";
						html+= "<td><input type='hidden' name='ward_period' class='ward_period' value='"+n.wardlist[i].ward_period +"'>"+n.wardlist[i].ward_period +"</td>";
						html+= "<td><input type='hidden' name='jupsoo_date' class='jupsoo_date' value='"+n.wardlist[i].jupsoo_date +"'>"+n.wardlist[i].jupsoo_date +"</td>";
						html+= "<td><input type='hidden' name='ward_date' class='ward_date' value='"+n.wardlist[i].ward_date +"'>"+n.wardlist[i].ward_date +"</td>";
						html+= "<td><input type='button' id='wardoutBtn' class='normalBtn' value='퇴원' onclick='wardout(this)'>";
						html+= "<input type='hidden' name='ward_list_id' class='ward_list_id' value='"+n.wardlist[i].ward_list_id +"'>";
						html+= "<input type='hidden' name='patient_id' class='patient_id' value='"+n.wardlist[i].patient_id +"'>";
						html+= "<input type='hidden' name='doctor_id' class='doctor_id' value='"+n.wardlist[i].doctor_id +"'>";
						html+= "<input type='hidden' name='w_soonap_id' class='w_soonap_id' value='"+n.wardlist[i].w_soonap_id +"'>";
						html+= "<input type='hidden' name='jupsoo_time' class='jupsoo_time' value='"+n.wardlist[i].jupsoo_time +"'></td></tr>";
						}
						html+= "</tbody></table>";
						$(".roomlist_div").append(html);
						$('#myTable').dataTable();
						
					}
				});
			} 
		
</script>
<div class="roomlist_div">
	<div class="roomlist_table">
		<table id="myTable" class="display">
			<thead>
				<tr>
					<th>접수번호</th>
					<th>환자명</th>
					<th>진료과</th>
					<th>의사명</th>
					<th>병실</th>
					<th>입원기간</th>
					<th>접수날짜</th>
					<th>입원날짜</th>
					<th>퇴원처리</th>
				</tr>
			</thead>
			<tbody id="tbody">
				<c:forEach items="${wardlist}" var="n">
					<tr>
						<td><input type='hidden' name='jupsoo_id' class='jupsoo_id'
							value='${n.jupsoo_id }'>${n.jupsoo_id }</td>
						<td><input type='hidden' name='name' class='name'
							value='${n.name }'>${n.name }</td>
						<td><input type='hidden' name='dept_name' class='dept_name'
							value='${n.dept_name }'>${n.dept_name }</td>
						<td><input type='hidden' name='doctor_name'
							class='doctor_name' value='${n.doctor_name }'>${n.doctor_name }</td>
						<td><input type='hidden' name='ward_num' class='ward_num'
							value='${n.ward_num }'>${n.ward_num }</td>
						<td><input type='hidden' name='ward_period'
							class='ward_period' value='${n.ward_period }'>${n.ward_period }</td>
	
						<td><input type='hidden' name='jupsoo_date'
							class='jupsoo_date' value='${n.jupsoo_date }'>${n.jupsoo_date }</td>
						<td><input type='hidden' name='ward_date' class='ward_date'
							value='${n.ward_date }'>${n.ward_date }</td>
						<td><input type='hidden' name='ward_list_id'
							class='ward_list_id' value='${n.ward_list_id }'> <input
							type='hidden' name='patient_id' class='patient_id'
							value='${n.patient_id }'> <input type='hidden'
							name='doctor_id' class='doctor_id' value='${n.doctor_id }'>
							<input type='hidden' name='w_soonap_id' class='w_soonap_id'
							value='${n.w_soonap_id }'> <input type='hidden'
							name='jupsoo_time' class='jupsoo_time' value='${n.jupsoo_time }'><input
							type="button" id="wardoutBtn" class="normalBtn" value="퇴원"
							onclick="wardout(this)"></td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>
</div>
